﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using DataAccess;

namespace InsuranceVehicle.UserSite
{
    public partial class UserMasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CustomerID"] != null)
            {
                open.Visible = false;
                close.Visible = false;
                logout.Visible = true;
                lblUsername.Text = "Welcome, " + Session["Firstname"].ToString();
                
            }
            else
            {
                logout.Visible = false;
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            CustomerDataAccess db = new CustomerDataAccess();
            CustomerInfo c = new CustomerInfo();
            c = db.CustomerLogin(txtCustAccount.Text, txtCustPassword.Text);
            if (c != null)
            {
                Session["CustomerID"] = c.CustomerID;
                Session["Firstname"] = c.Firstname;
                Session["Customer"] = c;
                Response.Redirect(Request.Url.ToString());
            }
            else
            {
                //lblError.Visible = true;
                //lblError.Text = "Account or password is incorrect";
                Response.Write("<script>alert('Account or password is incorrect')</script>");

                return;
            }    
        }

        protected void logout_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect(Request.Url.ToString());
        }

    }
}